*****************************************************************************************************
***Replication Files: Electoral Rules, Women's Representation and the Qualification of Politicians***
*****************************************************************************************************

*************
***Figures***
*************

use "~/Downloads/1987_2013_elected.dta", clear  
cd "~/Downloads"

*FIGURE 1 - SHARE WOMEN ALL LEVELS OVER TIME 

preserve
collapse male, by(lv_new year)
gen women = 1-male

label var women "Share of Women Politicians"

graph bar women if year == 1987 | year == 1992 | year == 1994 | year == 1996 | year == 2001 | year == 2006 | year == 2008 | year == 2013, over(year) ascategory blabel(total, format(%4.3f)) scheme(plotplain) 
* graph save "Graph" "~/Downloads/Figure1.gph", replace 
restore 


*FIGURE 2 - SHARE WOMEN SPLIT BY LEVEL OVER TIME 

preserve
collapse female, by(lv_new nat_elec_group)

label var female "Share of Women Politicians"
label var nat_elec_group "National Election Year"

twoway connected female nat_elec_group if lv_new == 1 || ///
connected female nat_elec_group if lv_new == 2 || ///
connected female nat_elec_group if lv_new == 3 || ///
connected female nat_elec_group if lv_new == 4 ///
||, legend (label(1 "municipal") label(2 "provincial") label(3 "regional") label(4 "national")) xline(2005) scheme(plotplain) xlabel(1987 1992 1994 1996 2001 2006 2008 2013) xline(2005)
* graph save "Graph" "~/Downloads/Figure2.gph", replace 
restore 


*FIGURE 3 - COUNT WOMEN SUBNATIONAL LEVELS

use "~/Downloads/1987_2013_elected.dta", clear  
cd "~/Downloads"

preserve
collapse (count) female, by( lv_new year)

label var female "Count of Women Politicians"
label var year "Years"

drop if year < 1996 
drop if year > 2008

twoway connected female year if lv_new == 1 || ///
connected female year if lv_new == 2 || ///
connected female year if lv_new == 3 || ///
||, legend (label(1 "municipal") label(2 "provincial") label(3 "regional")) xline(2005) scheme(plotplain) xlabel(1996 2001 2006 2008) xline(2005)
* graph save "Graph" "~/Downloads/Figure3.gph", replace 
restore


*FIGURE 4 - PARALLEL TRENDS, ALL LEVELS 

preserve
collapse female, by( nat_subnat year)

label var female "Share of Women Politicians"

drop if year < 1996
drop if year > 2011

twoway connected female year if nat_subnat == 1 || ///
connected female year if nat_subnat == 0 || ///
||, legend (label(1 "national") label(2 "subnational")) xline(2005) xscale(r(1996 2011))   xlabel(1996 2001 2006 2008) scheme(plotplain)
* graph save "Graph" "~/Downloads/Figure4.gph", replace 
restore 


*FIGURE 5 - PARALLEL TRENDS, SUBNATIONAL-NATIONAL 

preserve
collapse female, by(lv_new year)

label var female "Share of Women Politicians"

drop if year < 1996
drop if year > 2011

twoway connected female year if lv_new == 1 || ///
connected female year if lv_new == 2 || ///
connected female year if lv_new == 3 || ///
connected female year if lv_new == 4 ///
||, legend (label(1 "municipal") label(2 "provincial") label(3 "regional") label(4 "national")) xline(2005) xlabel(1996 2001 2006 2008) scheme(plotplain)
* graph save "Graph" "~/Downloads/Figure5.gph", replace 
restore 


*FIGURE 6 - AVERAGE EDUCATION SPLIT BY LEVELS AND GENDER 

preserve
collapse edu_lev, by(nat_elec_group male lv_new)

drop if edu_lev == . 
drop if male == . 
drop if lv_new == . 

label define lvl 1 "muni" 2 "prov" 3 "reg" 4 "nat" 
label values lv_new lvl

graph bar edu_level, ///
over(male,label(labsize(small))) ///
over(lv_new, label(angle(45))) ///
over(nat_elec_group, label(labsize(small))) ///
legend (label(1 "woman") label(2 "man"))   scheme(plotplain) 
* graph save "Graph" "~/Downloads/Figure6.gph", replace 
restore 


*FIGURE 7 - KERNEL DENSITY, QUALIFICATION NON-ELECTED VS ELECTED 

use "~/Downloads/2013_candidate_elected.dta", clear 

drop if edu_level == 5

twoway kdensity edu_lev if male == 0, bw(0.6) || kdensity edu_lev if male == 1, bw(0.6) scheme(plotplain)  ///
legend(label(1 "women") label(2 "men") ring(0) position(11)) title("PANEL A: ALL (CANDIDATES AND ELECTED)")  name(kernel1, replace)

twoway kdensity edu_level if male == 0 & eletto == 0, bw(0.6) || kdensity edu_lev if male == 1 & eletto== 0, bw(0.6) /// 
|| kdensity edu_lev if male == 0 & eletto== 1, bw(0.6) || kdensity edu_lev if male == 1 & eletto== 1, bw(0.6) scheme(plotplain) legend(ring(0) pos(11) ///
 label(1 "women cand.") label(2 "men cand.") label(3 "women elect.") label(4 "men elect.")) title("PANEL B: ELECTED vs. CANDIDATE POLITICIANS") name(kernel2, replace)
 
graph combine kernel1 kernel2
 * graph save "Graph" "/Users/elliewoodhouse/Downloads/Figure7.gph", replace 
 


